using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace hao_Model.Enums
{
    /// <summary>
    /// 枚举扩展方法类
    /// </summary>
    public static class EnumExtensions
    {
        /// <summary>
        /// 获取枚举值的Description特性值
        /// </summary>
        /// <param name="value">枚举值</param>
        /// <returns>Description特性值，如果没有则返回null</returns>
        public static string GetDescription(this Enum value)
        {
            return value.GetType()
                .GetMember(value.ToString())
                .FirstOrDefault()?
                .GetCustomAttribute<DescriptionAttribute>()?
                .Description;
        }
    }
}